package com.comdo.newup_loan.module.setting;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.comdo.newup_loan.R;
import com.comdo.newup_loan.base.BaseActivity;
import com.comdo.newup_loan.base.BasePresenter;
import com.comdo.newup_loan.util.DataCleanManager;
import com.comdo.newup_loan.util.TitleMenuUtil;

import butterknife.BindView;

/**
 * Created by liyuan on 2017/11/9.
 */

public class SettingActivity extends BaseActivity implements View.OnClickListener{
    @BindView(R.id.rl_message)
    RelativeLayout messageLayout;
    @BindView(R.id.rl_clear)
    RelativeLayout clearLayout;
    @BindView(R.id.rl_about)
    RelativeLayout aboutLayout;
    @BindView(R.id.rl_pass)
    RelativeLayout passLayout;
    @BindView(R.id.tv_cache)
    TextView mCacheText;
    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_setting;
    }

    @Override
    protected void init() {
        super.init();
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        new TitleMenuUtil(SettingActivity.this,"设置",true);
        messageLayout.setOnClickListener(this);
        clearLayout.setOnClickListener(this);
        aboutLayout.setOnClickListener(this);
        passLayout.setOnClickListener(this);
        MyCache();
    }

    @Override
    public BasePresenter getmPresenter() {
        return null;
    }

    @Override
    public void presenterSetView() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.rl_message:
                break;
            case R.id.rl_clear:
                DataCleanManager.clearAllCache(this);
                String dataSize = "";
                try {
                    dataSize = DataCleanManager.getTotalCacheSize(this);
                } catch (Exception e) {
                }
                mCacheText.setText(dataSize);
                showToast("清除完毕");
                break;
            case R.id.rl_about:
                toAboutActivity();
                break;
            case R.id.rl_pass:
                toPassActivity();
                break;
        }
    }
    // 计算缓存大小
    private void MyCache() {
        String dataSize = "";
        try {
            dataSize = DataCleanManager.getTotalCacheSize(this);
        } catch (Exception e) {
        }
        mCacheText.setText(dataSize);
    }
    private void toPassActivity(){
        Intent intent=new Intent(SettingActivity.this,ValidatePassActivity.class);
        startActivity(intent);
    }
    private void toAboutActivity(){
        Intent intent=new Intent(SettingActivity.this,AboutActivity.class);
        startActivity(intent);
    }
}
